package ui.activity.poscontrol.biz;

import java.util.List;

import base.BaseBiz;
import base.BaseResp;
import coom.BaseSubscribe;
import coom.RetrofitHelp;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import ui.activity.poscontrol.beanmodel.ChangeBankSelectListBean;
import ui.activity.poscontrol.beanmodel.MyPosBean;
import ui.activity.poscontrol.beanmodel.PosInfoBean;
import ui.activity.poscontrol.beanmodel.PushBackPeopleBean;
import ui.activity.poscontrol.beanmodel.PushBackPosBean;
import ui.activity.poscontrol.beanmodel.RedBallBean;
import ui.activity.poscontrol.beanmodel.RedBallnumBean;

/**
 * Created by fangjunsong on 19/3/19
 * 我的终端列表页面专用
 */


public class MyPosControlBiz extends BaseBiz {


    /**
     * 获取未激活列表
     */
    public void getUnactiveList(String customerId,int current,int size,String desc,String asc, final Callback<MyPosBean> callback) {
        com.add(RetrofitHelp.getSecretApi().queryMyNotActiveInfo(customerId,current,size,desc,asc)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<MyPosBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((MyPosBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((MyPosBean) obj);
                    }
                })
        );
    }
    /**
     * 获取其他设备列表
     * activeStatus :2:审核中；3：审核失败；4：已开通；5：已激活；6：已达标；
     */
    public void getPosInfoList(String customerId,int current,int size,int activeStatus , final Callback<PosInfoBean> callback) {
        com.add(RetrofitHelp.getSecretApi().queryPosInfo(customerId,current,size,activeStatus)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<PosInfoBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((PosInfoBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((PosInfoBean) obj);
                    }
                })
        );
    }
    /**
     * 定向划拨
     */
    public void Directionalallocation(RequestBody requestBody, final Callback<Boolean> callback) {
        com.add(RetrofitHelp.getSecretApi().directionalallocation(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Boolean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Boolean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Boolean) obj);
                    }
                })
        );
    }

    /**
     * 直接划拨
     */
    public void FlowDevices(RequestBody requestBody, final Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().flowDevices(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }
    /**
     * 查询可回拨终端设备
     */
    public void queryPushBackRecordPosData(String costomId,int targetId,String descs,String ascs,int type,final Callback<PushBackPosBean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/backFlow/records/" + targetId+"?customerId="+costomId+"&current=1&size=10000&descs="+descs+"&ascs="+ascs+"&type="+type;
        com.add(RetrofitHelp.getSecretApi().queryPushBackRecordPosInfo(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<PushBackPosBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((PushBackPosBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((PushBackPosBean) obj);
                    }
                })
        );
    }
    /**
     * 查询回拨记录终端人物信息
     * type 1 我发起的 2 我接收的
     */
    public void queryPushBackRecordPeopleData(String customId,int type,final Callback<List<PushBackPeopleBean>> callback) {
        com.add(RetrofitHelp.getSecretApi().queryPushBackRecordPeopleInfo(customId,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<List<PushBackPeopleBean>>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((List<PushBackPeopleBean>) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((List<PushBackPeopleBean>) obj);
                    }
                })
        );
    }
    /**
     * 查询回拨历史记录记录终端人物信息
     * type 1 我发起的 2 我接收的
     */
    public void queryPushBackHistoryRecordPeopleData(String customId,int type,final Callback<List<PushBackPeopleBean>> callback) {
        com.add(RetrofitHelp.getSecretApi().queryPushBackHistoryPeopleInfo(customId,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<List<PushBackPeopleBean>>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((List<PushBackPeopleBean>) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((List<PushBackPeopleBean>) obj);
                    }
                })
        );
    }
    /**
     * 查询回拨历史记录记录终端信息
     */
    public void queryPushBackHisToryRecordPosData(String costomId,int targetId,String descs,String ascs,int type,final Callback<PushBackPosBean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/backFlow/his/" + targetId+"?customerId="+costomId+"&current=1&size=10000&descs="+descs+"&ascs="+ascs+"&type="+type;
        com.add(RetrofitHelp.getSecretApi().queryPushBackHistoryPosInfo(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<PushBackPosBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((PushBackPosBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((PushBackPosBean) obj);
                    }
                })
        );
    }
    /**
     * 确认回拨
     */
    public void backFlowAllowDevices(RequestBody requestBody, final Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().backflowAllowDevices(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }
    /**
     * 拒绝回拨
     */
    public void backFlowDeAllowDevices(RequestBody requestBody, final Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().backflowDeAllowDevices(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }

    /**
     * 查询返现修改记录列表
     */
    public void getChangebanklist(int sign,int current,int size,final Callback<ChangeBankSelectListBean> callback) {
        com.add(RetrofitHelp.getSecretApi().getChangeBackList(sign,current,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<ChangeBankSelectListBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((ChangeBankSelectListBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((ChangeBankSelectListBean) obj);
                    }
                })
        );
    }

    /**
     * 获取红包列表
     * activeStatus :（1：有效；2：已使用；3：过期）
     */
    public void getRedBallList(int status,int current,int size, final Callback<RedBallBean> callback) {
        com.add(RetrofitHelp.getSecretApi().getRedballList(status,current,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<RedBallBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((RedBallBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((RedBallBean) obj);
                    }
                })
        );
    }

    /**
     * 查询红包数量
     */
    public void queryRedballNum(int id,final Callback<RedBallnumBean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/ticket/model/" + id;
        com.add(RetrofitHelp.getSecretApi().getRedballNum(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<RedBallnumBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((RedBallnumBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((RedBallnumBean) obj);
                    }
                })
        );
    }
    /**
     * 查询可用红包
     */
    public void queryCanUseRedball(int id,final Callback<RedBallBean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/tickets/enable/" + id+"?current=1&size=100";
        com.add(RetrofitHelp.getSecretApi().getCanUseRedball(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<RedBallBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((RedBallBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((RedBallBean) obj);
                    }
                })
        );
    }
}
